<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Sessionhelper extends CI_Model {
	function getSettings()
	{
		$session_id = $this->session->userdata('session_id');
		$this->db->where('session_id', $session_id);
		$query = $this->db->get('sessions');
		if ($query && ($query->num_rows() > 0))
		{
			$row = $query->result();
			$data = $row[0]->data;
			//$data = str_replace(PHP_EOL, "", $data);
			//echo $data;
			if ($data == "")
				return null;
			else
				return explode2(":", $data);
		} else {
			return null;
		}
	}
	function writeSettings($arr)
	{
		$session_id = $this->session->userdata('session_id');
		$this->db->where('session_id', $session_id);
		$query = $this->db->get('sessions');
		if ($query && ($query->num_rows() > 0))
		{
			//$this->db->reset();
			foreach($arr as $key => $element)
			{
				if ($element == "")
					unset($arr[$key]);
			}
			$new_data_arr = array(
				'data' => implode2(":", $arr)
			);
			$this->db->where("session_id", $session_id);
			$this->db->update('sessions', $new_data_arr);
			//$data = str_replace(PHP_EOL, "", $data);
			//echo $data
		} else {
			return null;
		}
	}
	function clearSettings()
	{
		$session_id = $this->session->userdata('session_id');
		$this->db->where('session_id', $session_id);
		$query = $this->db->get('sessions');
		if ($query && ($query->num_rows() > 0))
		{
			//$this->db->reset();
			$new_data_arr = array(
				'data' => ""
			);
			$this->db->where("session_id", $session_id);
			$this->db->update('sessions', $new_data_arr);
			//$data = str_replace(PHP_EOL, "", $data);
			//echo $data
		} else {
			return null;
		}
	}
}
?>